home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / VideoPlayer / Copy of Main.pas next >
Pascal/Delphi Source File  |  1998-02-06  |  6KB  |  221 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, Buttons, MPlayer, ComCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     MediaPlayer1: TMediaPlayer;
  12.     OpenBitBtn: TBitBtn;
  13.     BitBtn2: TBitBtn;
  14.     OpenDialog1: TOpenDialog;
  15.     AutoPlayCheckBox: TCheckBox;
  16.     AutoStartCheckBox: TCheckBox;
  17.     procedure OpenBitBtnClick(Sender: TObject);
  18.     procedure MediaPlayer1Notify(Sender: TObject);
  19.     procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
  20.       var DoDefault: Boolean);
  21.     procedure AutoPlayCheckBoxClick(Sender: TObject);
  22.     procedure FormCreate(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.     procedure SetMediaPlayerButtons;
  26.     procedure SetPlayButtonSet;
  27.   public
  28.     { Public declarations }
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. {$R *.DFM}
  37.  
  38. (*
  39.  
  40. AutoReplay:   Off
  41. Button  Open     Close    Play     Pause    Stop
  42. Play    ON       OFF      OFF      ON       ON
  43. Pause   OFF      OFF      ON       OFF      OFF
  44. Stop    OFF      OFF      ON       ON       OFF
  45. Next    ON       OFF      ON       ON       ON
  46. Prev    ON       OFF      ON       ON       ON
  47. Step    ON       OFF      ON       ON       ON
  48. Back    ON       OFF      ON       ON       ON
  49.  
  50.  
  51. AutoReplay:   On
  52. Button  Open     Close    Play     Pause    Stop
  53. Play    ON       OFF      OFF      ON       ON
  54. Pause   OFF      OFF      ON       OFF      OFF
  55. Stop    OFF      OFF      ON       ON       OFF
  56. Next    ON       OFF      OFF      ON       ON
  57. Prev    ON       OFF      OFF      ON       ON
  58. Step    ON       OFF      OFF      ON       ON
  59. Back    ON       OFF      OFF      ON       ON
  60.  
  61. *)
  62.  
  63. const
  64.   OpenButtonSet  : TButtonSet =
  65.     [
  66.       btPlay,
  67.       TMPBtnType(btNext),
  68.       TMPBtnType(btPrev),
  69.       btStep,
  70.       btBack
  71.     ];
  72.   CloseButtonSet : TButtonSet =
  73.     [
  74.     ];
  75.   PlayButtonSetNoReplay  : TButtonSet =
  76.     [
  77.       btPause,
  78.       btStop,
  79.       TMPBtnType(btNext),
  80.       TMPBtnType(btPrev),
  81.       btStep,
  82.       btBack
  83.     ];
  84.   PlayButtonSetReplay  : TButtonSet =
  85.     [
  86.       btPause,
  87.       btStop
  88.     ];
  89.   PauseButtonSet : TButtonSet =
  90.     [
  91.       btPlay,
  92.       btStop,
  93.       TMPBtnType(btNext),
  94.       TMPBtnType(btPrev),
  95.       btStep,
  96.       btBack
  97.     ];
  98.   StopButtonSet  : TButtonSet =
  99.     [
  100.       btPlay,
  101.       TMPBtnType(btNext),
  102.       TMPBtnType(btPrev),
  103.       btStep,
  104.       btBack
  105.     ];
  106.  
  107. var
  108.   PlayButtonSet: TButtonSet;     { Varies according to Autoplay checkbox }
  109.   CurrentButtonSet: TButtonSet;  { Holds set of enabled MediaPlayer buttons }
  110.  
  111. { Respond to user selection of the Open file button }
  112. procedure TForm1.OpenBitBtnClick(Sender: TObject);
  113. begin
  114.   if OpenDialog1.Execute then
  115.   begin
  116.     Form1.Caption := OpenDialog1.FileName;
  117.     MediaPlayer1.FileName := OpenDialog1.FileName;
  118.     MediaPlayer1.Open;
  119.     MediaPlayer1.Notify := True;
  120.     if AutoStartCheckBox.Checked then
  121.     begin
  122.       CurrentButtonSet := PlayButtonSet;
  123.       MediaPlayer1.Play;
  124.     end else
  125.     begin
  126.       CurrentButtonSet := OpenButtonSet;
  127.     end;
  128.     SetMediaPlayerButtons;
  129.   end;
  130. end;
  131.  
  132. procedure TForm1.MediaPlayer1Notify(Sender: TObject);
  133. begin
  134.   case MediaPlayer1.Mode of
  135.     mpNotReady :
  136.     begin
  137.       CurrentButtonSet := CloseButtonSet;
  138.     end;
  139.     mpStopped  :
  140.     begin
  141.       if AutoPlayCheckBox.Checked then
  142.       begin
  143.         MediaPlayer1.Rewind;
  144.         CurrentButtonSet := PlayButtonSet;
  145.         MediaPlayer1.Play;
  146.       end;
  147.     end;
  148.     mpPlaying  :
  149.     begin
  150.       CurrentButtonSet := PlayButtonSet;
  151.     end;
  152.     mpPaused   :
  153.     begin
  154.       CurrentButtonSet := PauseButtonSet;
  155.     end;
  156.     mpOpen     :
  157.     begin
  158.       CurrentButtonSet := OpenButtonSet;
  159.     end;
  160.   end;
  161.   SetMediaPlayerButtons;
  162.   MediaPlayer1.Notify := True;  { So we receive the next notify event }
  163. end;
  164.  
  165. procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
  166.   var DoDefault: Boolean);
  167. begin
  168.   MediaPlayer1.Notify := False;  { Do not change position of statement! }
  169.   if Button = btStop then
  170.   begin
  171.     MediaPlayer1.Stop;
  172.     CurrentButtonSet := OpenButtonSet;
  173.   end else
  174.   if Button = btPause then
  175.   begin
  176.     MediaPlayer1.Pause;
  177.     CurrentButtonSet := PauseButtonSet;
  178.   end;
  179.   SetMediaPlayerButtons;
  180. end;
  181.  
  182. procedure TForm1.AutoPlayCheckBoxClick(Sender: TObject);
  183. begin
  184.   if AutoPlayCheckBox.Checked then
  185.     MediaPlayer1.Notify := True;  { So media events trigger notification }
  186.   SetPlayButtonSet;  { Enable buttons according to checkbox state }
  187.   SetMediaPlayerButtons;
  188. end;
  189.  
  190. procedure TForm1.FormCreate(Sender: TObject);
  191. begin
  192. { Do not change the order of the following statements }
  193.   SetPlayButtonSet;       { Enable buttons according to checkbox state }
  194.   SetMediaPlayerButtons;  { Enable control buttons }
  195. end;
  196.  
  197. {- Private procedures }
  198.  
  199. { Enable MediaPlayerButtons according to program state }
  200. procedure TForm1.SetMediaPlayerButtons;
  201. begin
  202. { Do not change the order of the following statements }
  203.   if MediaPlayer1.Mode = mpPlaying then
  204.     CurrentButtonSet := PlayButtonSet;
  205.   MediaPlayer1.EnabledButtons := [];
  206.   MediaPlayer1.EnabledButtons := CurrentButtonSet;
  207. end;
  208.  
  209. { Change set of buttons based on auto-replay checkbox }
  210. procedure TForm1.SetPlayButtonSet;
  211. begin
  212. { Do not change the order of the following statements }
  213.   if AutoPlayCheckBox.Checked then
  214.     PlayButtonSet := PlayButtonSetReplay
  215.   else
  216.     PlayButtonSet := PlayButtonSetNoReplay;
  217.   SetMediaPlayerButtons;
  218. end;
  219.  
  220. end.
  221.